<?php
	/*==================================================================*/
	/*		文件名:admin.php                                    */
	/*		概要:页面         */
	/*==================================================================*/
	require "./FCKeditor/fckeditor.php"; // 用于载入FCKeditor类文件
	class WebpageAction extends CommonAction {
		private $oFCKeditor;
		private $column;
		private $webpage;
		function __construct(){
			parent::__construct();
			$this->column=new ColumnModel();
			$this->webpage=new WebpageModel();
			$this->oFCKeditor = new FCKeditor("content") ;          // 创建FCKeditor实例，可创建多个实例
			$this->oFCKeditor->BasePath = './FCKeditor/';      // 设置FCKeditor目录地址
		}
		
		
		
		
		//添加页面
		function add($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
			//记住选择的操作
			if(isset($_POST["jz"])){
				$this->assign("jz", "checked");
				$this->assign("colSelect", $this->column->buildSelect("pid", $_POST["pid"]));
			}else{
				$this->assign("colSelect", $this->column->buildSelect("pid"));
			}
		
			$this->assign("postTime",time());
			if($_POST["recommend"]){
				$this->assign("recommend", "checked");
				$this->assign("dis", "block");
			}else{
				$this->assign("no_recommend", "checked");
				$this->assign("dis", "none");
			}
			$this->assign("FCKeditor",$this->oFCKeditor->Create());
			$this->display("admin/webpage/add.tpl");
		}

				
		//插入
		function insert(){
			if($this->webpage->validateForm()){
				$_POST["postTime"]=strtotime($_POST["postTime"]);  //转为时间戳存入数据库
				//如果是推荐页面才设置幻灯播放
				if(!$_POST["recommend"]){
					$_POST["picId"]=0;	
				}
				if($this->webpage->add($_POST)){
					$this->add("页面添加成功！",1);
				}else{
					$this->add("页面添加失败！",0);
				}
			}else{
				$this->assign("post",$_POST);
				$this->oFCKeditor->Value=$_POST["content"];
	
				$this->add($this->webpage->getMessList(),0);
			}
		}

		//查看所有页面
		function edit($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '页面在添加后都处于锁定状态,只有审核后的页面才能发布.<br>审核后的页面也可以锁定,锁定的页面不被发布. ');
			}else{
				$this->message($status,$tmess);
			}
				
			$pid=isset($_REQUEST["pid"])?$_REQUEST["pid"]:1;
			//pr($pid);
			//$this->assign("colSelect", $this->column->buildSelect("pid", $pid, array("onChange"=>"window.location='admin.php?m=webpage&a=edit&pid='+options[selectedIndex].value")));
			$page=new Page("admin.php?m=webpage&a=edit&pid=".$pid."&",$this->webpage->total("where pid={$pid}"), PICTURE_PAGE_SIZE);	
			//查找所有页面
			$arts=$this->webpage->findAll(array("id","title","postTime","author", "pid","audit"), $page->getOffset(), PICTURE_PAGE_SIZE, "where 1=1");
			
			//$arts=$this->webpage->findAll(array("id","title","postTime","author", "pid","audit"), $page->getOffset(), PICTURE_PAGE_SIZE, "where pid={$pid}");
			
			$this->assign("pid", $pid);
			$cpage=isset($_GET["page"])?$_GET["page"]:1;
			$this->assign("page", $cpage);
			$this->assign("arts", $arts);
			$this->assign("fpage", $page->getPage());
			$this->display("admin/webpage/edit.tpl");
		}

		function mod($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
		
			$_POST=$this->webpage->find($_REQUEST["id"]);
			$this->assign("colSelect", $this->column->buildSelect("pid", $_POST["pid"]));
			$this->assign("post", $_POST);
			$this->assign("postTime",$_POST["postTime"]);
			if($_POST["recommend"]){
				$this->assign("recommend", "checked");
				$this->assign("picpath", GALLERY_PATH);
				$this->assign("dis", "block");
			}else{
				$this->assign("no_recommend", "checked");
				$this->assign("dis", "none");
			}

			$this->oFCKeditor->Value=$_POST["content"];
			$this->assign("FCKeditor",$this->oFCKeditor->Create());
			$this->display("admin/webpage/mod.tpl");
		}

		function update(){
			if($this->webpage->validateForm()){
				$_POST["postTime"]=strtotime($_POST["postTime"]);  //转为时间戳存入数据库
				//如果是推荐页面才设置幻灯播放
				if(!$_POST["recommend"]){
					$_POST["picId"]=0;	
				}
				if($this->webpage->mod($_POST)){
					$this->mod("修改页面成功！",1);
				}else{
					$this->mod("修改页面失败！",0);
				}
			}else{
				$this->mod($this->webpage->getMessList(),0);
			}		
		}
		function del(){
			if($this->webpage->del($_REQUEST["id"])){
				$this->edit($this->webpage->getMessList(),1);
			}else{
				$this->edit($this->webpage->getMessList(),0);
			}
		}

		
		
		
		//审核页面
		function audit(){
			if($this->webpage->audit($_REQUEST["id"],$_GET["status"])){
				$this->edit($this->webpage->getMessList(),1);
			}else{
				$this->edit($this->webpage->getMessList(),0);
			}
		}

		function fpro(){
			if(isset($_POST["audits_x"]) || isset($_POST["audits_y"])){
				$_GET["status"]=1;
				$this->audit();
			}elseif(isset($_POST["locks_x"]) || isset($_POST["locks_y"])){
				$_GET["status"]=0;
				$this->audit();
			}elseif(isset($_POST["dels_x"]) || isset($_POST["dels_y"])){
				$this->del();
			}	
		}
	}

